package com.ram.controller;

import com.ram.pojo.Accommodation;
import com.ram.pojo.AccommodationDTO;
import com.ram.pojo.AccommodationVO;
import com.ram.pojo.PageResult;
import com.ram.pojo.Result;
import com.ram.service.AccommodationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/accommodation")
public class AccommodationController {
    @Autowired
    private AccommodationService accommodationService;

    @GetMapping("/list")
    public Result list() {
        return Result.success(accommodationService.list());
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        return Result.success(accommodationService.getById(id));
    }

    @PostMapping
    public Result add(@RequestBody Accommodation accommodation) {
        accommodationService.add(accommodation);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Accommodation accommodation) {
        accommodationService.update(accommodation);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        accommodationService.deleteById(id);
        return Result.success();
    }

    // 分页+条件查询
    @PostMapping("/page")
    public Result pageQuery(@RequestBody AccommodationDTO dto) {
        PageResult<AccommodationVO> pageResult = accommodationService.pageQuery(dto);
        return Result.success(pageResult);
    }

    // 入住登记
    @PostMapping("/checkin")
    public Result checkin(@RequestBody Accommodation accommodation) {
        accommodationService.checkin(accommodation);
        return Result.success();
    }

    // 退宿
    @PostMapping("/checkout/{id}")
    public Result checkout(@PathVariable Integer id) {
        accommodationService.checkout(id);
        return Result.success();
    }

    // 调宿
    @PostMapping("/changeBed")
    public Result changeBed(@RequestParam Integer accommodationId, @RequestParam Integer newBedId, @RequestParam(required = false) String remark) {
        accommodationService.changeBed(accommodationId, newBedId, remark);
        return Result.success();
    }
} 